<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head th:include="include/includeTablebase"></head>
<body>
<!--     private String repairType;
    private String repairTypeState;
    private String repairState;
    private String beginTime;
    private String endTime; -->
<div class="panel-body" style="padding-bottom:0px;">
    <div class="panel panel-default">
        <div class="panel-heading">查询条件</div>
        <div class="panel-body">
            <form class="form-inline" role="form" style="float: left; width: 100%;" method="post" id="queryDecorationApply">
                <div class="form-group">
                    <label for="repairType">报修类型:</label>
                    <select class="form-control" name="repairType" id="repairType">
                            <option value = "-1">请选择</option>
                    </select>
                </div>
                <div class="form-group">
                    <label for="beginTime">申请时间从:</label>
                    <input type="date" class="form-control" name="beginTime" id="beginTime" />
                </div>
                <div class="form-group">
                    <label for="endTime">到:</label>
                    <input type="date" class="form-control" name="endTime" id="endTime"/>
                </div>
                <div class="form-group">
                    <label for="fixState">报修状态:</label>
                    <select class="form-control" name="fixState" id="fixState">
                        <option value = "-1">请选择</option>
                    </select>
                </div>
                <div class="form-group">
                    <button type="button" id="queryBtn" onclick="doQuery();" class="btn btn-primary">查询</button>
                </div>
            </form>
        </div>
    </div>
    <table id="decorationApply_table" style="margin-top: -50px;">
    </table>
</div>
<script th:inline="javascript">
    $(function () {
        setTimeout('initTable()', 100);
        $.post("dict/getType", {type: "REPAIR_TYPE"},
            function (r) {
                for (var i = 0; i <= r.data.length; i++) {
                    $("#repairType").append("<option value=" + r.data[i].value + ">" + r.data[i].text + "</option>");
                }
            });
        $.post("dict/getType", {type: "REPAIR_STATE"},
            function (r) {
                for (var i = 0; i <= r.data.length; i++) {
                    $("#fixState").append("<option value=" + r.data[i].value + ">" + r.data[i].text + "</option>");
                }
            });
    });

    function doQuery() {
        // 移除遮罩层的属性否则会导致在移动端无法显示滚动条
        $('body').removeClass("modal-open");
        $('#decorationApply_table').bootstrapTable('refresh');    //刷新表格
    }

    function initTable() {

        $.fn.bTableUtil({
            id: "decorationApply_table",
            url: "onlineRepairControl/list",
            formId: "queryDecorationApply",
            sortName: 'id',
            sortOrder: 'desc',
            pageSize : 5,
            toolbars: [
                {
                    text: '添加',
                    iconCls: 'glyphicon glyphicon-plus',
                    code: 'add_sys_decorationApply',
                    verify: false,// true 表示需要经过权限验证，false表示不需要经过权限验证
                    handler: function () {
                        window.Ewin.dialog({
                            title: "添加",
                            url: "onlineRepairControl/addPage",
                            gridId: "gridId",
                            width: 400,
                            height: 500
                        })
                    }
                },
                {
                    text: '修改',
                    iconCls: 'glyphicon glyphicon-pencil',
                    code: 'edit_sys_decorationApply',
                    verify: false,// true 表示需要经过权限验证，false表示不需要经过权限验证
                    handler: function () {
                        var rows = $('#decorationApply_table').bootstrapTable('getSelections');
                        if (rows.length == 0 || rows.length > 1) {
                            window.Ewin.alert({message: '请选择一条需要修改的数据!'});
                            return false;
                        }
                        if (rows[0].fixDate != null) {
                            window.Ewin.alert({message: '报修申请已经受理,您无权限再修改'});
                            return false;
                        }
                        window.Ewin.dialog({
                            title: "修改",
                            url: "onlineRepairControl/updatePage?id=" + rows[0].id,
                            gridId: "gridId",
                            width: 400,
                            height: 500
                        });
                    }
                },
                {
                    text: '删除',
                    iconCls: 'glyphicon glyphicon-remove',
                    code: 'remove_sys_decorationApply',
                    verify: false,// true 表示需要经过权限验证，false表示不需要经过权限验证
                    handler: function () {
                        var rows = $('#decorationApply_table').bootstrapTable('getSelections');
                        if (rows.length == 0) {
                            window.Ewin.alert({message: '请选择一条需要删除的数据!'});
                            return false;
                        }
                        if (rows[0].fixDate != null) {
                            window.Ewin.alert({message: '报修申请已经受理,您无权限删除'});
                            return false;
                        }
                        window.Ewin.confirm({title: '提示', message: '是否要删除您所选择的记录？', width: 500}).on(function (e) {
                            if (e) {
                                $.post("onlineRepairControl/removeBath", {json: JSON.stringify(rows)}, function (e) {
                                    if (e.result) {
                                        window.Ewin.alert({message: e.msg});
                                        doQuery();
                                    }
                                });
                            }
                        });
                    }
                },
                {
                    text: '重新加载',
                    iconCls: 'glyphicon glyphicon-record',
                    verify: false,
                    handler: function () {
                        window.Ewin.confirm({title: '提示', message: '是否要需要重新加载数据？', width: 500}).on(function (e) {
                            if (e) {
                                $.post("onlineRepairControl/reload", function (e) {
                                    if (e.result) {
                                        window.Ewin.alert({message: e.msg});
                                    }
                                });
                            }
                        });
                    }
                }
            ],
            columns: [
                {
                    checkbox: true
                },
                {
                    field: '',
                    title: '序号',
                    visible: false,
                    formatter: function (value, row, index) {
                        console.log(value);
                        return index + 1;
                    }
                },
                {
                    field: 'repairName',
                    title: '报修人',
                    align: 'center',
                    valign: 'middle',
                    sortable: true
                },
                {
                    field: 'repairTel',
                    title: '报修人电话',
                    align: 'center',
                    valign: 'middle',
                    sortable: true
                },
                {
                    field: 'repairDate',
                    title: '报修时间',
                    align: 'center',
                    valign: 'middle',
                    sortable: true,
                    formatter: function (value, row, index) {
                        var unixTimestamp = new Date(value);
                        return unixTimestamp.toLocaleString();
                    }
                },
                {
                    field: 'title',
                    title: '报修标题',
                    align: 'center',
                    valign: 'middle',
                    sortable: true
                },
                {
                    field: 'descInf',
                    title: '备注',
                    align: 'center',
                    valign: 'middle',
                    visible: false,
                    sortable: true
                },
                {
                    field: 'repairTypeName',
                    title: '报修项目名称',
                    align: 'center',
                    valign: 'middle',
                    sortable: true
                },
                {
                    field: 'repairType',
                    title: '报修类型',
                    align: 'center',
                    valign: 'middle',
                    sortable: true
                },
                {
                    field: 'fixName',
                    title: '维修人',
                    align: 'center',
                    valign: 'middle',
                    sortable: true
                },
                {
                    field: 'fixTel',
                    title: '维修人电话',
                    align: 'center',
                    valign: 'middle',
                    sortable: true
                },
                {
                    field: 'fixDate',
                    title: '派遣时间',
                    align: 'center',
                    valign: 'middle',
                    sortable: true,
                    formatter: function (value, row, index) {
                        if(value != null){
                            var unixTimestamp = new Date(value);
                            return unixTimestamp.toLocaleString();
                        }else{
                            return '';
                        }

                    }
                },
                {
                    field: 'fixState',
                    title: '报修状态',
                    align: 'center',
                    valign: 'middle',
                    sortable: true
                },
                {
                    field: 'refuseReason',
                    title: '拒绝原因',
                    align: 'center',
                    valign: 'middle',
                    visible: false,
                    sortable: true
                }

                         ]
        });
    }
</script>
</body>
</html>